#!/bin/bash
source_functions()
{
        . conf/itennis.conf
        . scripts/log_print
        . scripts/exec_remote
}

source_functions
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=${HOSTS_CONF}
BG='n'
read -p "please input permission value [e.g. 750 or !750]: "
perm=${REPLY}
if [ "$perm" == "" ];
then
	log ERROR "permission is not null"
	exit
fi
if [[ "`echo $perm | cut -c 1`" == '!' ]];then
        dnots='!'
        perm=`echo $perm | cut -c2-${#perm}`
fi

read -p "please input director value [e.g. /tmp]: "
dir=$REPLY
if [ "$dir" == "" ];
then
        log ERROR "director is not null"
        exit
fi

read -p "please input user value [e.g. root or !root]: "
users=$REPLY
if [[ "$users" == "" ]];then
	utmp=""
else
	if [[ "`echo $users | cut -c 1`" == '!' ]];then
        	unots='!'
        	users=`echo $users | cut -c2-${#users}`
		utmp="$unots -user $users"
	else
		utmp="-user $users"
	fi
fi

(
cat << EOF
find $dir $dnots -perm ${perm} $utmp -ls
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $bg
rm /tmp/*.$$
